define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wdgroup/wdcate/index',
                    add_url: 'wdgroup/wdcate/add',
                    edit_url: 'wdgroup/wdcate/edit',
                    del_url: 'wdgroup/wdcate/del',
                    multi_url: 'wdgroup/wdcate/multi',
                    table: 'wdcate',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [{checkbox: true},
                    {field: 'id', title: __('Id'),operate: false,},
                    {field: 'name', title: __('Name')},
                    {field: 'pid', title: __('上级分类'),visible: false,
                        addclass: 'selectpage',
                        extend: 'data-source="wdgroup/wdcate/selectpage" data-select-only="true" data-field="name" data-params=\'{"custom[status]":"normal","custom[pid]":"0"}\'"  ',
                        formatter: Table.api.formatter.search},
                    {field: 'prantname', title: __('上级分类'),operate: false,},
                    {field: 'image', title: __('缩略图'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                    {field: 'user_level_id', title: __('用户组'),  visible: false,
                        addclass: 'selectpage',
                        extend: 'data-source="user/group/index" data-field="name" data-select-only="true"',
                        formatter: Table.api.formatter.search},
                    {field: 'user_level_text', title: __('用户组'), operate: false, formatter: Table.api.formatter.label},
                    {field: 'weigh', title: __('Weigh'),operate: false,},
                    {field: 'status', title: __('Status'), operate: false, formatter: Table.api.formatter.status},
                    {
                        field: 'operate',
                        title: __('Operate'),
                        table: table,
                        events: Table.api.events.operate,
                        formatter: Table.api.formatter.operate
                    }]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});